#!/usr/bin/env python 

""""
Copyright 2010-2011 Vincent Gauthier
Email: vincent.gauthier@telecom-sudparis.eu
"""

# Import Regular Expression
import re

"""
Things to remember about regular expression
===========================================

. (dot) : any character
\w : any word character (a-z,A-Z,1-9)
\d : any digit (0-9)
\s : white space
\S : non white space character
+ : 1 or more
* : 0 or more
"""


# Test simple patern Matching
match = re.search("iig","called piiig, and xuidgs")

if match:
    print match.group()
else:
    print "Not Found"
    
# Test a more complicated patern Matching
match = re.search('..gs','called piiig, and xuidgs')

if match:
    print match.group()
else:
    print "Not Found"

    
# Test a more complicated patern Matching
match = re.search(r':\w+','bla bla :cat :123 bla bla   ')

if match:
    print match.group()
else:
    print "Not Found"

# Test a more complicated patern Matching
match = re.search(r'\d\s+\d\s+\d','bla bla :cat : 1   2  3 bla bla   ')

if match:
    print match.group()
else:
    print "Not Found"

# Test a more complicated patern Matching
match = re.search(r'([\w.-]+)@([\w.-]+)','bla bla vincent.gauthier@it-sudparis.eu : 1   2  3 bla bla   ')

if match:
    print match.group()
    print match.group(1)
    print match.group(2)
else:
    print "Not Found"


# Test a more complicated patern Matching
match = re.findall(r'([\w.-]+)@([\w.-]+)','bla bla vincent.gauthier@it-sudparis.eu : 1   2  3 bla bla  xxx@gmail.com ')

if match:
    print match
else:
    print "Not Found"
